﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text.RegularExpressions;

public partial class CMS_Control_PartControl : System.Web.UI.UserControl
{
    #region 外部属性
    private ShowMode _Type = ShowMode.Type;
    private ShowMode _Border = ShowMode.Border;
    private ShowMode _Article = ShowMode.Article;

    public enum ShowMode : int
    {
        Type = 1,
        Border = 2,
        Article = 3,
        add

    }

    public ShowMode Type
    {
        get
        {
            return _Type;
        }
        set
        {
            _Type = value;
        }
    }


    public ShowMode Border
    {
        get
        {
            return _Border;
        }
        set
        {
            _Border = value;
        }
    }

    public ShowMode Article
    {
        get
        {
            return _Article;
        }
        set
        {
            _Article = value;
        }
    }
    #endregion

    Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.cmsBorder bo = new Usas.BLL.Cms.cmsBorder();
    Usas.BLL.Cms.cmsType tp = new Usas.BLL.Cms.cmsType();
    Usas.Model.Cms.cmsArticle arm = new Usas.Model.Cms.cmsArticle();
    Usas.Model.Cms.cmsBorder bom = new Usas.Model.Cms.cmsBorder();
    Usas.Model.Cms.cmsType tpm = new Usas.Model.Cms.cmsType();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.BLL.Cms.cms_purview_setting cps = new Usas.BLL.Cms.cms_purview_setting();
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 显示类型区块
    /// </summary>
    /// <param name="SM">类别（Type、border...）</param>
    /// <param name="id">编号</param>
    /// <param name="view">显示权限</param>
    /// <param name="edit">编辑权限</param>
    /// <param name="ck">是否已经审核</param>
    /// <param name="ckk">是否需要审核</param>
    public void IntiPart(Usas.Common.Cms.Role.RedType rt, int id)
    {
        string name = "";
        bool del = true;
        bool ischeck = true;
        string RT = "";
        string ros = "";
        bool edit = false;
        bool view = false;
        DataSet ds = null;
        bool aat = false;
        bool ason = false;
        bool sv = false;
        string pic = "";
        int _num = 0;
        switch (rt)
        {
            case Usas.Common.Cms.Role.RedType.Article:
                arm.ArtId = id;
                arm = ar.GetModel(arm.ArtId);
                RT = Usas.Common.Cms.Role.RedType.Article.ToString();

                ds = cps.GetList("p_table='a' and p_pid=" + id.ToString());
                if (ds != null && ds.Tables[0] != null)
                {
                    ros = ro.GetSelfSettingRole();
                    edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
                    view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
                }

                if (!view)
                {
                    cont.Visible = false;
                }
                else
                {

                    arm = ar.GetModel(id);
                    name = arm.ArtTopic;

                    del = arm.CanView;
                    ischeck = false;
                    _num = Convert.ToInt32(arm.ArtOrder);
                    PicChoose.Visible = false;
                    CheckTr.Visible = false;
                    hidtype.Value = arm.TypeId.ToString();
                    hidborder.Value = arm.BorderId.ToString();
                    hidart.Value = arm.ArtId.ToString();
                    hidartp.Value = arm.ParentArtId.ToString();
                    AddSon.CommandArgument = ShowMode.Article.ToString();
                    if (!edit)
                    {
                        aat = false;
                        ason = false;
                        sv = false;
                    }
                    else
                    {
                        aat = true;
                        ason = true;
                        sv = true;
                    }
                }
                mode.Value = RT;
                break;
            case Usas.Common.Cms.Role.RedType.Border:
                bom = bo.GetModel(id);
                RT = Usas.Common.Cms.Role.RedType.Border.ToString();
                mode.Value = RT;

                ds = cps.GetList("p_table='b' and p_pid=" + id.ToString());
                if (ds != null && ds.Tables[0] != null)
                {
                    ros = ro.GetSelfSettingRole();
                    edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
                    view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
                }

                if (!view)
                {
                    cont.Visible = false;
                }
                else
                {
                    PicChoose.Visible = true;
                    pic = bom.ImgFile == null || bom.ImgFile.Trim().Length <= 0 ? "" : bom.ImgFile.Trim();
                    name = bom.BorderName;
                    del = bom.Del;
                    ischeck = bom.IsCheck;
                    SelUser1.ReadOnly(bom.CheckPerson.ToString());
                    hidtype.Value = bom.TypeId.ToString();
                    hidborder.Value = bom.BorderId.ToString();
                    hidart.Value = "0";
                    hidIsCheck.Value = bom.IsCheck ? "1" : "0";
                    AddSon.CommandArgument = ShowMode.Article.ToString();
                    _num = bom.BorderOrder;
                    if (!edit)
                    {
                        aat = false;
                        ason = false;
                        sv = false;
                    }
                    else
                    {
                        aat = true;
                        ason = true;
                        sv = true;
                    }
                }
                break;
            case Usas.Common.Cms.Role.RedType.Type:
                RT = Usas.Common.Cms.Role.RedType.Type.ToString();

                mode.Value = RT;
                ischeck = false;
                if (id == -1)
                {
                    AddSon.CommandArgument = ShowMode.Type.ToString();
                    name = "Hyperion";
                    //viewrole = "D0";
                    //editrole = System.Configuration.ConfigurationManager.AppSettings["AdminRoleEmpId"].ToString();
                    del = false;


                    CheckTr.Visible = false;
                    Save.Visible = false;
                    AddAct.Visible = false;
                    AddSon.Visible = true;
                    DoSave.Visible = true;

                    if (cinfo.GetSuperAdminGroup())
                    {
                        aat = false;
                        ason = true;
                        sv = false;
                    }

                }
                else
                {
                    AddSon.CommandArgument = ShowMode.Border.ToString();
                    tpm = tp.GetModel(id);

                    ds = cps.GetList("p_table='t' and p_pid=" + id.ToString());
                    if (ds != null && ds.Tables[0] != null)
                    {
                        ros = ro.GetSelfSettingRole();
                        edit = ds.Tables[0].Select(ros + " and p_type='1'", "p_id").Length > 0 ? true : false;
                        view = ds.Tables[0].Select(ros + " and p_type='0'", "p_id").Length > 0 ? true : false;
                    }

                    if (!view)
                    {
                        cont.Visible = false;
                    }
                    else
                    {
                        name = tpm.TypeName;
                        //pic = tpm.ImgFile == null || tpm.ImgFile.Trim().Length <= 0 ? "" : tpm.ImgFile.Trim();
                        PicChoose.Visible = true;
                        pic = tpm.ImgFile == null || tpm.ImgFile.Trim().Length <= 0 ? "" : tpm.ImgFile.Trim();
                        del = tpm.Del;
                        CheckTr.Visible = false;
                        _num = tpm.TypeOrder;
                        hidtype.Value = tpm.TypeId.ToString();
                        DoCheck.Visible = false;
                        hidIsCheck.Value = "0";
                    }

                    if (!edit)
                    {
                        aat = false;
                        ason = false;
                        sv = false;
                    }
                    else
                    {
                        aat = false;
                        ason = true;
                        sv = true;
                    }
                }

                break;
        }
        topic.Text = name;
        GetPic1.Pic = pic;
        if (id != -1)
        {
            SetRole1.SetValue(id, (Usas.Common.Cms.Role.RedType)Enum.Parse(typeof(Usas.Common.Cms.Role.RedType), RT));
            SetRoleEdit1.SetValue(id, (Usas.Common.Cms.Role.RedType)Enum.Parse(typeof(Usas.Common.Cms.Role.RedType), RT));
        }
        shifouxianshi.Checked = !!del;
        shifoushenhe.Checked = ischeck;

        AddSon.Visible = ason;
        AddAct.Visible = aat;
        Save.Visible = sv;
        txtNum.Text = _num.ToString();

        AddSon.Attributes.Add("onclick", "return confirm('在【" + name + "】目录下添加子目录？')");
        AddAct.Attributes.Add("onclick", "return confirm('在【" + name + "】目录下添加文章？')");

        if (!!shifouxianshi.Checked)
        {
            Del.Visible = true;
        }
        /*
        string name = "";
        string viewrole = "";
        string editrole = "";
        bool del = true;
        bool ischeck = true;
        //DoSave.Visible = edit == "t" ? true : false;
        //DoCheck.Visible = edit == "t" ? true : false;
        string RT = "";

        switch (SM)
        {
            case ShowMode.Type:

                RT = Usas.Common.Cms.Role.RedType.Type.ToString();
                if (id == -1)
                {
                    name = "USAS";
                    viewrole = "D0";
                    editrole = System.Configuration.ConfigurationManager.AppSettings["AdminRoleEmpId"].ToString();
                    del = false;


                    CheckTr.Visible = false;
                    Save.Visible = false;
                    AddAct.Visible = false;
                    AddSon.Visible = true;
                    DoSave.Visible = true;

                    AddSon.CommandArgument = ShowMode.Type.ToString();
                    AddSon.Attributes.Add("onclick", "return confirm('在【Hyperion】目录下添加子目录？')");
                    if (cinfo.GetEmpId() != editrole)
                    {
                        AddSon.Visible = false;
                        DoSave.Visible = false;

                    }
                }
                else
                {
                    tpm = tp.GetModel(id);
                    name = tpm.TypeName;
                    viewrole = tpm.Purview;
                    editrole = tpm.EditPurview;
                    del = tpm.Del;
                    CheckTr.Visible = false;

                    hidtype.Value = tpm.TypeId.ToString();
                    DoCheck.Visible = false;
                    hidIsCheck.Value = "0";

                    AddSon.CommandArgument = ShowMode.Border.ToString();
                    AddSon.Attributes.Add("onclick", "return confirm('在【" + tpm.TypeName + "】目录下添加子目录？')");
                }
                break;
            case ShowMode.Border:
                RT = Usas.Common.Cms.Role.RedType.Border.ToString();

                bom = bo.GetModel(id);
                name = bom.BorderName;
                viewrole = bom.ViewPurview;
                editrole = bom.EditPurview;
                del = bom.Del;
                ischeck = bom.IsCheck;
                SelUser1.ReadOnly(bom.CheckPerson.ToString());
                hidtype.Value = bom.TypeId.ToString();
                hidborder.Value = bom.BorderId.ToString();
                hidart.Value = "0";
                hidIsCheck.Value = bom.IsCheck ? "1" : "0";


                AddSon.CommandArgument = ShowMode.Article.ToString();
                AddSon.Attributes.Add("onclick", "return confirm('在【" + bom.BorderName + "】目录下添加子目录？')");


                AddAct.Attributes.Add("onclick", "return confirm('在【" + bom.BorderName + "】目录下添加文章？')");
                break;
            case ShowMode.Article:

                RT = Usas.Common.Cms.Role.RedType.Article.ToString();

                arm = ar.GetModel(id);
                name = arm.ArtTopic;
                viewrole = arm.ArtViewPurview;
                editrole = arm.ArtEditPurview;
                del = arm.CanView;
                ischeck = false;
                iscarryon = true;

                CheckTr.Visible = false;
                hidtype.Value = arm.TypeId.ToString();
                hidborder.Value = arm.BorderId.ToString();
                hidart.Value = arm.ArtId.ToString();
                hidartp.Value = arm.ParentArtId.ToString();
                hidIsCheck.Value = ckk;

                AddSon.CommandArgument = ShowMode.Article.ToString();
                AddSon.Attributes.Add("onclick", "return confirm('在【" + arm.ArtTopic + "】目录下添加子目录？')");


                AddAct.Attributes.Add("onclick", "return confirm('在【" + arm.ArtTopic + "】目录下添加文章？')");
                break;
        }
        mode.Value = SM.ToString();
        */


    }

    protected void AddAct_Click(object sender, EventArgs e)
    {
        switch ((ShowMode)Enum.Parse(typeof(ShowMode), mode.Value, true))
        {
            case ShowMode.Article:
                Response.Redirect("ViewContent.aspx?action=a&type=a&t=" + hidtype.Value + "&b=" + hidborder.Value + "&id=" + hidart.Value);
                break;
            case ShowMode.Border:
                Response.Redirect("ViewContent.aspx?action=a&type=b&t=" + hidtype.Value + "&b=" + hidborder.Value + "&id=" + hidart.Value);
                break;
        }

    }

    protected void AddSon_Click(object sender, EventArgs e)
    {
        AddInti();
    }

    private void AddInti()
    {
        topic.Text = "";

        mode.Value = "add";
        Save.Visible = true;
        if (AddSon.CommandArgument == ShowMode.Border.ToString() || AddSon.CommandArgument == ShowMode.Type.ToString())
        {
            CheckTr.Visible = true;
            PicChoose.Visible = true;
        }
        else
        {
            CheckTr.Visible = false;
            PicChoose.Visible = false;
        }
        txtNum.Text = "";
        AddSon.Visible = false;
        AddAct.Visible = false;
        GetPic1.Pic = "";
        shifoushenhe.Checked = false;
        shifouxianshi.Checked = false;
        shifouxianshi.Enabled = false;
    }

    private void AddInti(int id)
    {
        //IntiPart(ShowMode.add, id, "t", "t", "0", "0");

        topic.Text = "";

        shifoushenhe.Checked = false;
        shifouxianshi.Checked = !true;
        shifouxianshi.Enabled = false;
        mode.Value = "add";
        Save.Visible = true;
        if (AddSon.CommandArgument == ShowMode.Border.ToString())
        {
            CheckTr.Visible = true;
        }
        else
        {
            CheckTr.Visible = false;
        }


        Del.Visible = false;

    }

    protected void Save_Click(object sender, EventArgs e)
    {
        if (SaveAction(true))
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('修改成功！');location.href='" + Request.Url.ToString() + "'", true);
        }
    }

    private bool AddSonClass(bool IsBack)
    {
        bool flag = false;
        string ValStr = "";
        int backid = 0;
        switch ((ShowMode)Enum.Parse(typeof(ShowMode), AddSon.CommandArgument.ToString(), true))
        {
            case ShowMode.Article:
                ValStr = Val();
                if (ValStr.Length <= 0)
                {
                    arm.ArtTopic = topic.Text;
                    arm.ArtDirectory = hidtype.Value + "\\" + hidborder.Value + hidart == "0" ? "" : "\\" + hidart.Value;
                    arm.BorderId = Convert.ToInt32(hidborder.Value);
                    arm.TypeId = Convert.ToInt32(hidtype.Value);
                    arm.ParentArtId = Convert.ToInt32(hidart.Value);
                    arm.ModfiyTime = DateTime.Now;
                    arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
                    arm.Writer = Convert.ToInt32(cinfo.GetEmpId());
                    arm.Audit = false;
                    arm.ArtFormat = 1;
                    arm.CanView = false;
                    arm.ArtOrder = Convert.ToInt32(DateTime.Now.ToString("yyyyMMddHH"));
                    arm.IsVersion = false;
                    arm.ShowOrder = false;
                    arm.PublishStatus = 1;
                    arm.ArtOrder = (txtNum.Text != "" ? Convert.ToInt32(txtNum.Text) : arm.ArtOrder);
                    backid = ar.Add(arm);
                    if (backid > 0)
                    {
                        SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), backid, Usas.Common.Cms.Role.RedType.Article);
                        SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backid, Usas.Common.Cms.Role.RedType.Article);
                        flag = true;
                    }
                }
                else
                {
                    flag = false;
                }
                break;
            case ShowMode.Border:
                ValStr = Val();
                if (ValStr.Length <= 0)
                {
                    bom.TypeId = Convert.ToInt32(hidtype.Value);
                    bom.BorderName = topic.Text;
                    bom.BorderOrder = Convert.ToInt32(DateTime.Now.ToString("yyMMddHH"));
                    bom.ImgFile = GetPic1.Pic;
                    bom.Del = false;
                    bom.IsCheck = shifoushenhe.Checked;
                    bom.BorderOrder = (txtNum.Text != "" ? Convert.ToInt32(txtNum.Text) : bom.BorderOrder);
                    backid = bo.Add(bom);
                    if (backid > 0)
                    {
                        SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), backid, Usas.Common.Cms.Role.RedType.Border);
                        SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backid, Usas.Common.Cms.Role.RedType.Border);
                        flag = true;
                    }
                }
                else
                {
                    flag = false;
                }
                break;
            case ShowMode.Type:
                ValStr = Val();
                if (ValStr.Length <= 0)
                {
                    tpm.TypeName = topic.Text;
                    tpm.TypeOrder = Convert.ToInt32(DateTime.Now.ToString("yyMM"));
                    tpm.ImgFile = null;
                    tpm.TypeKey = null;
                    tpm.Del = false;
                    tpm.TypeOrder = (txtNum.Text != "" ? Convert.ToInt32(txtNum.Text) : tpm.TypeOrder);
                    tpm.ImgFile = GetPic1.Pic;
                    backid = tp.Add(tpm);
                    if (backid > 0)
                    {
                        SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), backid, Usas.Common.Cms.Role.RedType.Type);
                        SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backid, Usas.Common.Cms.Role.RedType.Type);
                        flag = true;
                    }
                }
                else
                {
                    flag = false;
                }
                break;
        }

        if (flag)
        {
            if (IsBack)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('添加成功！');parent.location.href=parent.location.href", true);

            }

            return true;

        }
        else
        {
            if (ValStr.Length > 0)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "！')", true);
            }
            return false;
        }
    }

    protected void Del_Click(object sender, EventArgs e)
    {
        int count = 0;
        switch ((ShowMode)Enum.Parse(typeof(ShowMode), mode.Value, true))
        {
            case ShowMode.Article:
                ar.Delete(Convert.ToInt32(hidart.Value));
                break;
            case ShowMode.Border:
                bo.Delete(Convert.ToInt32(hidborder.Value));
                break;
            case ShowMode.Type:
                tp.Delete(Convert.ToInt32(hidtype.Value));
                break;
        }
        this.Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('删除成功');parent.location.reload()", true);
        //Response.Redirect("~/CMS/Admin/Info.aspx?info=" + Server.UrlEncode("删除成功!"));

    }

    /// <summary>
    /// 增改验证（必须）
    /// </summary>
    /// <returns></returns>
    public string Val()
    {
        if (topic.Text.Trim().Length <= 0)
        {
            return "栏目名称不得为空";
        }


        if (shifoushenhe.Checked)
        {
            if (SelUser1.EmployeeId == "" || SelUser1.EmployeeId == "0")
            {
                return "请选择审核人！";
            }
        }
        if (txtNum.Text.Trim() != "" && !System.Text.RegularExpressions.Regex.IsMatch(txtNum.Text, "^[0-9]*$"))
        {
            return "排序必须为正整数！";
        }

        if (SetRole1.Check().Trim().Length > 0)
        {
            return SetRole1.Check();
        }

        if (SetRoleEdit1.Check().Trim().Length > 0)
        {
            return SetRoleEdit1.Check();
        }



        return "";
    }

    public void SetDel(bool Vis)
    {
        Del.Visible = Vis;
    }

    public bool SaveAction(bool IsBack)
    {
        string ValStr = "";
        switch ((ShowMode)Enum.Parse(typeof(ShowMode), mode.Value, true))
        {
            case ShowMode.Article:

                ValStr = Val();
                if (ValStr.Length <= 0)
                {
                    arm.ArtTopic = topic.Text;
                    arm.ArtDirectory = hidtype.Value + "\\" + hidborder.Value + hidart == "0" ? "" : "\\" + hidart.Value;
                    arm.BorderId = Convert.ToInt32(hidborder.Value);
                    arm.TypeId = Convert.ToInt32(hidtype.Value);
                    arm.ArtId = Convert.ToInt32(hidart.Value);
                    arm.ParentArtId = Convert.ToInt32(hidartp.Value);

                    arm.ModfiyTime = DateTime.Now;
                    arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
                    arm.Writer = null;
                    arm.Audit = false;
                    arm.ArtFormat = 1;
                    arm.CanView = !!shifouxianshi.Checked;
                    arm.ArtOrder = Convert.ToInt32(txtNum.Text);
                    arm.IsVersion = false;
                    arm.ShowOrder = false;



                    ar.Update(arm);

                    SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);
                    SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), Convert.ToInt32(arm.ArtId), Usas.Common.Cms.Role.RedType.Article);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "')", true);
                    return false;
                }
                break;
            case ShowMode.Border:


                ValStr = Val();
                if (ValStr.Length <= 0)
                {

                    bom.TypeId = Convert.ToInt32(hidtype.Value);
                    bom.BorderId = Convert.ToInt32(hidborder.Value);
                    bom.BorderOrder = Convert.ToInt32(txtNum.Text);
                    bom.BorderName = topic.Text;
                    bom.ImgFile = null;
                    bom.Del = !!shifouxianshi.Checked;
                    bom.IsCheck = shifoushenhe.Checked;
                    bom.ImgFile = GetPic1.Pic;
                    if (!bom.IsCheck)
                    {
                        bom.CheckPerson = 0;
                    }
                    else
                    {
                        if (SelUser1.EmployeeId != "")
                        {
                            bom.CheckPerson = Convert.ToInt32(SelUser1.EmployeeId);
                        }
                    }
                    bo.Update(bom);

                    SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), Convert.ToInt32(bom.BorderId), Usas.Common.Cms.Role.RedType.Border);
                    SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), Convert.ToInt32(bom.BorderId), Usas.Common.Cms.Role.RedType.Border);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "')", true);
                    return false;
                }


                break;
            case ShowMode.Type:
                ValStr = Val();
                if (ValStr.Length <= 0)
                {

                    tpm.TypeId = Convert.ToInt32(hidtype.Value);
                    tpm.TypeName = topic.Text;
                    tpm.TypeOrder = Convert.ToInt32(txtNum.Text);
                    tpm.ImgFile = null;
                    tpm.TypeKey = null;
                    tpm.Del = !!shifouxianshi.Checked;
                    tpm.ImgFile = GetPic1.Pic;
                    tp.Update(tpm);

                    SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), Convert.ToInt32(tpm.TypeId), Usas.Common.Cms.Role.RedType.Type);
                    SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), Convert.ToInt32(tpm.TypeId), Usas.Common.Cms.Role.RedType.Type);

                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('" + ValStr + "')", true);
                    return false;
                }
                break;
            case ShowMode.add:
                return AddSonClass(IsBack);
                break;
        }
        return true;
    }

    public bool AddAction(Usas.Common.Cms.Role.RedType rt, int id)
    {
        int tid = 0;
        int bid = 0;
        int pid = 0;

        switch (rt)
        {
            case Usas.Common.Cms.Role.RedType.Article:
                arm = ar.GetModel(id);
                tid = arm.TypeId;
                bid = arm.BorderId;
                pid = Convert.ToInt32(arm.ArtId);
                break;
            case Usas.Common.Cms.Role.RedType.Border:
                bom = bo.GetModel(id);
                tid = bom.TypeId;
                bid = bom.BorderId;
                pid = 0;
                break;
        }
        int backid = 0;
        arm.ArtTopic = topic.Text;
        arm.ArtDirectory = hidtype.Value + "\\" + hidborder.Value + hidart == "0" ? "" : "\\" + hidart.Value;
        arm.BorderId = Convert.ToInt32(bid);
        arm.TypeId = Convert.ToInt32(tid);
        arm.ParentArtId = Convert.ToInt32(pid);
        arm.ModfiyTime = DateTime.Now;
        arm.Modify = Convert.ToInt32(cinfo.GetEmpId());
        arm.Writer = Convert.ToInt32(cinfo.GetEmpId());
        arm.Audit = false;
        arm.ArtFormat = 1;
        arm.CanView = false;
        arm.ArtOrder = Convert.ToInt32(DateTime.Now.ToString("yyyyMMddHH"));
        arm.IsVersion = false;
        arm.ShowOrder = false;
        arm.PublishStatus = 1;
        backid = ar.Add(arm);

        if (backid > 0)
        {
            SetRole1.SetValueTran(SetRoleEdit1.GetList(), SetRole1.GetList(), backid, Usas.Common.Cms.Role.RedType.Article);
            SetRoleEdit1.SetValueTran(SetRoleEdit1.GetList(), backid, Usas.Common.Cms.Role.RedType.Article);
            return true;
            //flag = true;
        }
        else
        {
            return false;
        }
    }

    public void UserIntiPart(Usas.Common.Cms.Role.RedType rt, int id, bool IsEdit)
    {
        if (IsEdit)
        {
            IntiPart(rt, id);
        }
        else
        {
            AddInti();
            SetRole1.SetValue(id, rt);
            SetRoleEdit1.SetValue(id, rt);
        }
        DoSave.Visible = false;
        DoCheck.Visible = false;
    }
}
